from selenium import webdriver
from selenium.webdriver.firefox.options import Options
import json
import time

driver = webdriver.Edge(executable_path="./driver/msedgedriver.exe")
driver.get("https://app.buaa.edu.cn/uc/wap/login?redirect=https%3A%2F%2Fapp.buaa.edu.cn%2Fsite%2FbuaaStudentNcov%2Findex")
inputList = driver.find_elements_by_tag_name("input")
pressbutton = driver.find_element_by_class_name("btn")
try:
    with open("password.txt","r") as f:
        load = json.load(f)
    username = load["username"]
    password = load["password"]
except:
    username = input("username: ")
    password = input("password: ")
    d = {"username":username,"password":password}
    with open("password.txt","w") as f:
        json.dump(d,f)

inputList[0].send_keys(username)
inputList[1].send_keys(password)
pressbutton.click()
print(driver.get_cookies())
# driver2 = webdriver.Chrome()
# driver.get("https://app.buaa.edu.cn/site/buaaStudentNcov/index")
time.sleep(3)
driver.find_elements_by_tag_name("input")[0].click()
# print(driver.find_elements_by_tag_name("a")[0].text)
time.sleep(2)
driver.find_elements_by_tag_name("a")[0].click()
time.sleep(2)
driver.find_elements_by_tag_name('div')[-1].click()
#driver.quit()

if __name__ == "__main__":
    pass